<%
require "src/historico"
require "src/timestamp"

def show_logs_msg historicos %>
  <div class="post">
    <h1 class="title">Log de Downloads</h1>
    <div class="entry">
      <div id="demo"><br/>
        <table id="example" border="0" cellpadding="0" class="display" align="center">
          <thead>
            <tr>
              <th>#</th>
              <th>Data</th>
              <th>Processo</th>
              <th>Mensagem</th>
            </tr>
          </thead>
          <tbody> <%
            historicos.each do |h|
              print "<tr>\n<td>#{h.id}</td>\n"
              print "<td>#{h.data}</td>\n"
              print "<td>#{h.processo}</td>\n"
              print "<td>#{h.mensagem}</td>\n</tr>\n"
            end %>
          </tbody>
          <tfoot>
            <tr>
              <th colspan="4" align="center">
                Página gerada em <%= StrTime.now %><br/>
                RS-Online ~ version 1.0b ~ Powered by eRuby
              </th>
            </tr>
          </tfoot>
        </table>
      </div>
      <div class="meta">
        <p class="links"></p>
      </div>
    </div>
  </div> <%
end

def puts_error msg%>
  <div class="post">
    <div class="entry">
      <h1 class="title">Ocorreu um erro.</h1>
      <p><%= msg %></p>
  <%#*<p>Não foi possível carregar a página. Contate o administrador!</p>%>
    </div>
  </div>
<%
end

def run
  begin
    historicos = Historico.select_top(200)
    if historicos == nil or historicos == []
      puts_error "Histórico vazio."
    else
      show_logs_msg historicos
    end
  rescue Exception => err
    puts_error "Erro:</b> #{err} <br/><br/>#{err.backtrace.each { |i| print i, "<br/>" }}"
  end
end
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : Professional
Description: A two-column, fixed-width design with dark color scheme background.
Version    : 1.0
Released   : 20081230

-->

<html>
  <head>
    <link rel="icon" href="images/favicon.png" type="image/x-icon" />
    <link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
    <!-- PAGINAÇÃO VIA AJAX -->
    <style type="text/css" title="currentStyle">
      @import "pagination/css/demo_page.css";
      @import "pagination/css/demo_table.css";
    </style>
    <script type="text/javascript" language="javascript" src="pagination/js/jquery.js"></script>
    <script type="text/javascript" language="javascript" src="pagination/js/jquery.dataTables.js"></script>
    <script type="text/javascript" charset="utf-8">
      $(document).ready(function() {
        $('#example').dataTable( {
          "sPaginationType": "full_numbers"
        } );
      } );
    </script>
    <!-- PAGINAÇÃO VIA AJAX -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>RS-Online ~ version 1.0b ~ Powered by eRuby</title>
    <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
  </head>
  <body>

    <div id="wrapper">

      <div id="header">
        <div id="logo">
          <h1><a href="#">RS-Online Beta</a></h1>
          <p>version 1.0b ~ Powered by eRuby</p>
        </div>
        <!-- end #logo -->
        <div id="menu">
          <ul>
            <li class="active"><a href="index.rhtml">Home</a></li>
            <li><a href="#">About Us</a></li>
            <li><a href="#">Products</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Contact Us</a></li>
          </ul>
        </div>
        <!-- end #menu -->
      </div>
      <!-- end #header -->
      <div id="page">
        <!--<div id="header-pic"></div>-->
        <div id="content">
          <% run %>
        </div>
        <!-- end #content -->
        <div id="sidebar">
          <div id="sidebar-bgtop"></div>
          <div id="sidebar-content">
            <div id="sidebar-bgbtm">
              <ul>
                <li id="search">
                  <h2>Search</h2>
                  <form method="get" action="">
                    <fieldset>
                      <input type="text" id="s" name="s" value="" />
                      <input type="submit" id="x" value="Search" />
                    </fieldset>
                  </form>
                </li>
                <li>
                  <h2>Pacotes</h2>
                  <ul>
                    <li><a href="add_pacote.rhtml"><img alt="new" src="images/package_add.png"/>&nbsp;Novo Pacote</a></li>
                    <li><a href="lista_pacotes.rhtml"><img alt="lst" src="images/drive_web.png"/>&nbsp;Lista de Pacotes</a></li>
                    <li><a href="lista_pacotes_ocultos.rhtml"><img alt="oct" src="images/safe.png"/>&nbsp;Lista de Pacotes Ocultos</a></li>
                  </ul>
                </li>
                <li>
                  <h2>Downloads</h2>
                  <ul>
                    <li><a href="#"><img alt="est" src="images/chart_bar.png"/>&nbsp;Estatística (em construção)</a></li>
                    <li><a href="log_downloads.rhtml"><img alt="log" src="images/report.png"/>&nbsp;Log de Downloads</a></li>
                  </ul>
                </li>
              </ul>
            </div>
          </div>
        </div>
        <!-- end #sidebar -->
        <div style="clear:both; margin:0;"></div>
      </div>
      <!-- end #page -->

    </div>

    <div id="footer">
      <p>&copy; 2010. All Rights Reserved. Design by Nightcrawler. RS-Online is powered by eRuby.</p>
    </div>
    <!-- end #footer -->
  </body>
</html>